package mashuaiproject.mashuaiproject.schedule;

import mashuaiproject.mashuaiproject.mapper.UserMapper;
import mashuaiproject.mashuaiproject.model.Users;
import mashuaiproject.mashuaiproject.serivce.JMontiorSerivce;
import mashuaiproject.mashuaiproject.serivce.OtherSeivce;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.List;

@Component

public class HotTagesTasks {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private JMontiorSerivce jMontiorSerivce;
    //每天三点执行排行榜功能
   // @Scheduled(fixedRate = 100000)
    @Scheduled(cron = "0 05 03 ? * *")
    public void testTasks() {
        System.out.println("定时任务执行时间：");
        //查找所有用户
        List<Users> usersList=userMapper.selecAllUser2();
        //统计每个用户的总积分
        for(Users users:usersList){
            Integer exp=userMapper.selectByExp(users.getId());
            Integer jifen=userMapper.selectByJifen(users.getId());
            Integer weiwang=userMapper.selectByWeiwang(users.getId());
            Integer count=exp+jifen+weiwang;
            //将信息更新到数据库
            Integer updateCount=userMapper.updateRanking(users.getId(),count);

        }
        //查找积分更新后的用户,并且降序查找
        List<Users> usersList2=userMapper.selecAllUser3();
        for(int i=0;i<usersList2.size();i++){
            //更新排名
            Integer updatePaiming=userMapper.updateWeekRenking(usersList2.get(i).getId(),i+1);
            //给前十名每个用户发送一条排名动态
            Integer insert =jMontiorSerivce.insertDongtai(usersList2.get(i).getId(),8,i+1);//用户id，动态类型，不集体类型
            System.err.println("更排名成功："+updatePaiming);
        }
        //更新后定时的插入动态变化里面


    }


}
